<?php
// +----------------------------------------------------------------------
// | makePHP 
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://makephp.org All rights reserved.
// +----------------------------------------------------------------------
// | Licensed BSD.(http://www.make.org/BSD-license.txt)
// +----------------------------------------------------------------------
// | Author: 叁石(sanshi) <sanshi0815@tom.com>
// | Author: 白家昌<baijc2004cn@126.com>
// +----------------------------------------------------------------------
/**
 * 工厂类
 * @name    Factory
 * @see         
 * @version	1.0.0 
 * @author	sanshi
 */
 
Class Factory
{
	    /**
	     *  取得memcache
	     * */
		public static function getMemcache()
		{
				
				$include_file = LIB_BASE_PATH."MemcacheBase.class.php";
				if(!file_exists($include_file)) exit($include_file."不存在");
				require_once($include_file);
				return new MemcacheBase();
		}
		public static function getMemcached()
		{
				if (class_exists("Memcached"))
				{
					global $memcacheConfig;
					$mc = new Memcached();
					$mc->addServer($memcacheConfig[0]['server'],$memcacheConfig[0]['port']);
					$mc->setOption(Memcached::OPT_COMPRESSION, false);
					return $mc;
				}else{
					exit("this server not load memcached!");
				}
		}
		/**
		 * 取得对应的表
		 * @name  getDB
		 * @param string $db_name 数据表名
		 * @return object 数据库对象
		 * */
		public static function getDB($db_name)
		{
				$TableName = 'DB_'.strtolower($db_name);
				$include_file = LIB_DB_PATH."{$TableName}.class.php";
				if(!file_exists($include_file)) exit($include_file."不存在");
				require_once(LIB_BASE_PATH."PdoMysql.class.php");
				//require_once(LIB_BASE_PATH."AdoMysql.class.php");
				require_once($include_file);
				return new $TableName();
		}
		/**
		 * 取得smarty
		 * @name getSmarty
		 * @return object  smarty对象
		 * */
		public static function getSmarty()
		{
				$include_file = LIB_BASE_PATH."TplObject.class.php";
				if(!file_exists($include_file)) exit($include_file."不存在");
				require_once($include_file);
				return new TplObject();
		}
		/**
		 * 取得fck
		 * @name  getFck
		 * @param string $fckName  fck 实例名字
		 * @param  string $content  fck 显示的内容 默认为空
		 * @param string  $barSet   fck现在菜单
		 * @return  object fck 对象
		 * */
		public static function getFck($fckName,$content="",$barSet="Default")
		{
			include_once(FCK_PATH."fckeditor.php");
			$fck = new FCKeditor($fckName);
			$fck->BasePath = HOST_PATH."drivers/fckeditor/";
			$fck->Width = "100%";
			$fck->Height = "300px";
			$fck->Value = $content;
			$fck->ToolbarSet	= $barSet ;//Basic
			return $fck->CreateHtml();
		}
		/**
		 * 取得基础类
		 * @name    getBaseClass
		 * @param   $className  基础类名
		 * @return  object      基础类对象   
		 * */
		public static function getBaseClass($className)
		{
				$include_file = LIB_BASE_PATH."{$className}.class.php";
				if(!file_exists($include_file)) exit($include_file."不存在");
				require_once($include_file);
				return new $className();
		}
		/**
		 * 取得项目类
		 * @name    getItemClass
		 * @param 	$className    项目类型
		 * @return  object        项目类对象
		 * */
		public static function getItemClass($className)
		{
				$include_file = LIB_ITEM_PATH."{$className}.class.php";
				if(!file_exists($include_file)) exit($include_file."不存在");
				require_once($include_file);
				return new $className();
		}
		/**
        *取得后台逻辑层
        * @name  getAdminClass()
        * @return object session 工厂对象
        * */
		public static function getAdminClass($className)
		{
			$include_file = ADMIN_PATH."include/{$className}.class.php";
			if(!file_exists($include_file)) return Factory::getAdminClass('index');
			require_once($include_file);
			return new $className();
		}
       /**
        *取得session工厂并完成session的适配
        * @name  getSession
        * @return object session 工厂对象
        * */
		public static function getSession()
		{
			@session_start();
			$session = Factory::getBaseClass('sessionFartory');
			$session->set(SESSION_TYPE);
			return $session;
		}
}
?>
